﻿je_company_independence = {
	icon = "gfx/interface/icons/event_icons/event_colonial.dds"

	is_shown_when_inactive = {
		is_subject_type = subject_type_chartered_company
	}

	possible = {
		is_subject_type = subject_type_chartered_company
	}

    invalid = {	
		is_subject = yes
		NOT = { is_subject_type = subject_type_chartered_company }
	}

	fail = {
		is_subject = no
	}

	on_fail = {
		custom_tooltip = {
			text = company_collapse_tt
		
			if = {
				limit = {
					c:RAC = ROOT
				}

				every_in_list = {
					variable = past_overlord 
					trigger_event = { id = journal_flavor_company_collapse.4 }
				}

			 

			}
			else_if = {
				limit = {
					c:NWT = ROOT
				}

				every_in_list = {
					variable = past_overlord 
					trigger_event = { id = journal_flavor_company_collapse.2 }
				}

			}
			else_if = {
				limit = {
					c:COL = ROOT
				}
					every_in_list = {
					variable = past_overlord 
					trigger_event = { id = journal_flavor_company_collapse.3 }
				}

			}
			else_if = {
				limit = {
					c:HBC = ROOT
				}

				every_in_list = {
					variable = past_overlord 
					trigger_event = { id = journal_flavor_company_collapse.1 }
				}
				
			}
			else_if = {
				limit = {
					c:RNC = ROOT
				}
				
				every_in_list = {
					variable = past_overlord 
					trigger_event = { id = journal_flavor_company_collapse.5 }
				}


			}
			else_if = {
				limit = {
					c:IAC = ROOT
				}

				every_in_list = {
					variable = past_overlord 
					trigger_event = { id = journal_flavor_company_collapse.7 }
				}

			}
			else_if = {
				limit = {
					c:GEA = ROOT
				}
				every_in_list = {
					variable = past_overlord 
					trigger_event = { id = journal_flavor_company_collapse.8 }
				}
			}
			else_if = {
				limit = {
					c:BSA = ROOT
				}
				every_in_list = {
					variable = past_overlord 
					trigger_event = { id = journal_flavor_company_collapse.6 }
				}
			}
			else_if = {
				limit = {
					c:RGT = ROOT
				}

				every_in_list = {
					variable = past_overlord 
					trigger_event = { id = journal_flavor_company_collapse.9 }
				}

			}
			else_if = {
				limit = {
					OR = {
						c:BIC = ROOT
					}
				}

				every_in_list = {
					variable = past_overlord 
					trigger_event = { id = journal_flavor_company_collapse.10 }
				}

			}
			else_if = {
				limit = {
					OR = {
						c:MPR = ROOT
					}
				}

				every_in_list = {
					variable = past_overlord 
					trigger_event = { id = journal_flavor_company_collapse.11 }
				}

			}
			else_if = {
				limit = {
					OR = {
						c:BPR = ROOT
					}
				}

				every_in_list = {
					variable = past_overlord 
					trigger_event = { id = journal_flavor_company_collapse.12 }
				}

			}
		
		}
	}

	on_weekly_pulse = {
		effect = {
			clear_variable_list = past_overlord
			add_to_variable_list = { name = past_overlord target = top_overlord }
		}
	}

	weight = 1000 
}

je_autonomy = {
	icon = "gfx/interface/icons/event_icons/event_industry.dds"

	is_shown_when_inactive = {
		is_subject_type = subject_type_chartered_company
		NOT = {
			OR = {
				c:BIC = ROOT
				AND = {
					c:MPR = ROOT
					c:MPR = {
						overlord = c:BIC
					}
				}
				AND = {
					c:BPR = ROOT
					c:BPR = {
						overlord = c:BIC
					}
				}	
			}
		}
	}

    possible = {
		GDP >= 1000000
	}

	fail = {
		in_default = yes
	}

    complete = {	
		NOT = {has_law = law_type:law_autocracy}
		any_scope_pop = {
			standard_of_living > 15
			strata = poor
		}
	}

	invalid = {
		NOT = { is_subject_type = subject_type_chartered_company }
	}

    on_complete = {
		top_overlord = {
			create_diplomatic_pact = {
				country = root
				type = dominion
			}
		}
		if = {
			limit = {
				c:RAC = ROOT
			}
			change_tag = AKA
		}	
		else_if = {
			limit = {
				c:HBC = ROOT
			}
			change_tag = CAN
		}	
		else_if = {
			limit = {
				c:RNC = ROOT
			}
			change_tag = NGR
		}
		else_if = {
			limit = {
				c:GEA = ROOT
			}
			change_tag = TZN
		}
		else_if = {
			limit = {
				c:COL = ROOT
			}
			change_tag = ORG
		}
		else_if = {
			limit = {
				c:RGT = ROOT
			}
			change_tag = GRN
		}
	}

	status_desc = {
		first_valid = {
			triggered_desc = {
				desc = je_autonomy_status
			}
		}
	}
    should_be_pinned_by_default = yes
	weight = 1000
}

je_rac_hbc_deal = {
	icon = "gfx/interface/icons/event_icons/event_diplomacy.dds"

	is_shown_when_inactive = {
		exists = c:RAC
		c:RAC = root
	}

    possible = {
		OR = {
			AND = {
				exists = c:NWT 
				c:NWT = {
					relations:root < relations_threshold:cordial
				} 
			}
			AND = {
				exists = c:COL
				c:COL = {
					relations:root < relations_threshold:cordial
				} 
			}
			AND = {
				exists = c:HBC
				c:HBC = {
					relations:root < relations_threshold:cordial
				} 
			}
		}

	}

	fail = {
		custom_tooltip = {
			text = rac_agreement_fail_tt
			has_variable = rac_agreement_fail
		}
		
	}

	invalid = {
		AND = {
			AND = {
				NOT = { exists = c:HBC }
				c:HBC = {
					NOT = { is_subject_of = c:GBR }
				}
			}
			AND = {
				NOT = { exists = c:NWT }
				c:NWT = {
					NOT = { is_subject_of = c:GBR }
				}
			}
			AND = {
				NOT = { exists = c:COL }
				c:COL = {
					NOT = { is_subject_of = c:GBR }
				}
			}	
		}
	}

	immediate = {
        set_variable = {
			name = hbc_deal_var
			value = 0
		}
		trigger_event = {
			id = journal_flavor_rac.1
		}
    }

	current_value = {
		value = root.var:hbc_deal_var
	}

	on_timeout = {
		trigger_event = {
			id = journal_flavor_rac.3
		}
	}

	timeout = 1825

	weight = 10000
}

je_company_bankruptcy = {
	icon = "gfx/interface/icons/event_icons/event_skull.dds"

	is_shown_when_inactive = {
		is_subject_type = subject_type_chartered_company
	}

    possible = {
		taking_loans = yes
	}

	fail = {
		in_default = yes
	}

	invalid = {
		NOT = { is_subject_type = subject_type_chartered_company }
	}

    on_fail = {
		top_overlord = {
			create_diplomatic_pact = {
				country = root
				type = puppet
			}
		}
		if = {
			limit = {
				c:RAC = ROOT
			}
			change_tag = AKA
		}	
		else_if = {
			limit = {
				c:BIC = ROOT
			}
			top_overlord = {
				trigger_event = { id = raj.1 }
			}
		}
		else_if = {
			limit = {
				c:HBC = ROOT
			}

			if = {
				limit = { exists = c:ONT }
				random_scope_state = {
					limit = {
						state_region = s:STATE_ONTARIO
					}
					set_state_owner = c:ONT
				}
			}
			if = {
				limit = { exists = c:QUE }
				random_scope_state = {
					limit = {
						state_region = s:STATE_QUEBEC
					}
					set_state_owner = c:QUE
				}
			}

		}	
		else_if = {
			limit = {
				c:RNC = ROOT
			}
			change_tag = NGR
		}
		else_if = {
			limit = {
				c:RGT = ROOT
			}
			change_tag = GRN
		}
		else_if = {
			limit = {
				c:BSA = ROOT
			}

			if = { 
				limit = {
					NOT = {
						any_scope_state = {
							OR = {
								state_region = s:STATE_ZAMBIA
								state_region = s:STATE_KAZEMBE
							}
						}	
					}
				}
				change_tag = RHO
			}
			else = {
				change_tag = ZAM

				if = {
					limit = {
						any_scope_state = {
							state_region = s:STATE_ZAMBEZI
						}	
					}
					create_country = {
						tag = RHO
						origin = this
						state = s:STATE_ZAMBEZI.region_state:ZAM
					}
					top_overlord = {
						create_diplomatic_pact = {
						country = c:RHO
						type = puppet
						}
					}
				}
			}



		}
		else_if = {
			limit = {
				c:IAC = ROOT
			}
			change_tag = KNY

			if = {
				limit = {
					any_scope_state = {
						state_region = s:STATE_UGANDA
					}	
				}
				create_country = {
					tag = UGA
					origin = this
					state = s:STATE_UGANDA.region_state:KNY
				}
				top_overlord = {
					create_diplomatic_pact = {
					country = c:UGA
					type = puppet
					}
				}
			}

		}

	}

	status_desc = {
		first_valid = {
			triggered_desc = {
				desc = je_bankruptcy_status
			}
		}
	}
    should_be_pinned_by_default = yes
	weight = 1000
}


je_relocate_bic = {
	icon = "gfx/interface/icons/event_icons/event_trade.dds"

	is_shown_when_inactive = {
		exists = c:BIC
		NOT = {
			c:BIC = {
				is_player = yes
			}
		}
		OR = {
			AND = {
				exists = c:BPR
				c:BPR = root
			}
			AND = {
				exists = c:MPR
				c:MPR = root
			}
		}
	}

    possible = {
		overlord = c:BIC
		overlord = {
			is_subject_type = subject_type_chartered_company
		}
	}

	complete = {
		overlord = {
			root.gdp >this.gdp 
		}
	}


	invalid = {
		OR = {
			NOT = {
				overlord = c:BIC
			}
			overlord = {
				NOT = {is_subject_type = subject_type_chartered_company}
			}
			NOT = {is_subject_type = subject_type_chartered_company}
		}
	}

	on_complete = {
		annex = c:BIC
		change_tag = BIC

		if = {
			limit = {
				exists = c:MPR
				NOT = {
					c:MPR = ROOT
				}
			}
			create_diplomatic_pact = {
				country = c:MPR
				type = dependency
			}	
		}
		if = {
			limit = {
				exists = c:BPR
				NOT = {
					c:BPR = ROOT
				}
			}
			create_diplomatic_pact = {
				country = c:BPR
				type = dependency
			}	
		}
	}

	weight = 10000
}